package com.hsd.znsh.converter;

import com.hsd.znsh.entity.Gateway;
import com.hsd.znsh.entity.Sensor;
import com.hsd.znsh.enums.OnlineStatusEnum;
import com.hsd.znsh.pojo.output.GatewayVO;
import com.hsd.znsh.pojo.output.SensorVO;
import com.hsd.znsh.repository.HostRepository;
import com.hsd.znsh.repository.SensorTypeRepository;
import com.hsd.znsh.repository.UserRepository;
import com.hsd.znsh.utils.BeanUtil;
import com.hsd.znsh.utils.EnumUtil;

import java.util.ArrayList;
import java.util.List;

/*
 * @auther: wangjiacai
 *
 * @create: 2018-04-25 13:54:52
 */
public class GatewayConverter {

    public static GatewayVO converterToGatewayVO(Gateway gateway, HostRepository hostRepository){
        if(gateway==null) return null;
        GatewayVO gatewayVO=new GatewayVO();
        BeanUtil.copyProperties(gateway,gatewayVO);
        if(gateway.getHostId()!=null){
            gatewayVO.setHostName(hostRepository.findOne(gateway.getHostId()).getHostName());
        }
        gatewayVO.setOnlineStatusString(EnumUtil.getMessageByCode(gateway.getOnlineStatus(),OnlineStatusEnum.class));
        return gatewayVO;
    }

    public static List<GatewayVO> converterToGatewayVOList(List<Gateway> gateways, HostRepository hostRepository){
        List<GatewayVO> list=new ArrayList<>();
        for(Gateway gateway:gateways){
            list.add(converterToGatewayVO(gateway,hostRepository));
        }
        return list;
    }
}
